package com.gmrz.uap.jfinal.interceptor;

import com.gmrz.uap.common.UAPSSOHelper;
import com.gmrz.uap.model.User;
import com.gmrz.uap.model.UserRole;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

public class SuperAdminAuthInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {
        User user = UAPSSOHelper.getUserByUapSessionId(inv.getController().getRequest());
        boolean isSuperAdmin = UserRole.dao.isSuperAdmin(user.getUserId());
        if (!isSuperAdmin) {
            inv.getController().forwardAction("/");
        }

        inv.invoke();
    }
}
